#ifndef FRUSTUM_H_
#define FRUSTUM_H_

#include "Plane.h"
#include <d3dx9.h>

class Frustum
{
public:
    Frustum();
    void SetProjectionInternalsPerspective(float angle, float ratio, float nearD, float farD);
    void SetProjectionInternalsOrthographic(float width, float height, float nearD, float farD);
    void SetViewInternals(const Vec3& pos, const Vec3& look, const Vec3& up);
    void Draw()const;
    int IsPointInFrustum(const Vec3& q);
    int IsSphereInFrustum(const Vec3& q, const float& rad)const;
    int IsBoxInFrustum(D3DXMATRIXA16& transform, D3DXVECTOR3& min,D3DXVECTOR3& max)const;

private:

    enum{
        TOP = 0,
        BOTTOM,
        LEFT,
        RIGHT,
        NEARP,
        FARP    };

public:

    static enum{ OUTSIDE, INSIDE, ON };

private:
    //The 6 planes of the frustum
    Plane m_planes[6];
    //The eight corners of the frustum
    Vec3 m_ntl,m_ntr,m_nbl,m_nbr;
    Vec3 m_ftl,m_ftr,m_fbl,m_fbr;
    //The frustum stats
    float m_nearD, m_farD, m_ratio, m_angle, m_tang;
    float m_nw, m_nh, m_fw, m_fh;

};

#endif